<?php slot('contact') ?>
<?php use_javascripts_for_form($form) ?>
<?php use_stylesheets_for_form($form) ?>
<div id="contact_errors"></div>
<div class="tagasisidebox">

	<form id="contact_form" method="post" action="<?php echo LinkGen::getInstance(LinkGen::RAW_ACTION)->link(null, array('module' => 'contact', 'action' => 'submit')) ?>">
		<?php echo $form->renderHiddenFields(true) ?>
			<?php echo $form['parent']->render(array('class' => 'sideinput','placeholder' => $form->getWidgetSchema()->getLabel('parent')))?>
			<?php echo $form['child']->render(array('class' => 'sideinput','placeholder' => $form->getWidgetSchema()->getLabel('child')))?>
			<?php echo $form['birthday']->renderLabel('',array('class' => 'sideinput')); ?>
			<?php echo $form['birthday']->render()?>
			<?php echo $form['email']->render(array('class' => 'sideinput','placeholder' => $form->getWidgetSchema()->getLabel('email')))?>
			<?php echo $form['phone']->render(array('class' => 'sideinput','placeholder' => $form->getWidgetSchema()->getLabel('phone')))?>
			<?php echo $form['message']->render(array('class' => 'areatext','placeholder' => $form->getWidgetSchema()->getLabel('message')))?>
			<?php echo $form['captcha']->render(array('id'=>'contact_captcha', 'class' => 'codein','placeholder' => $form->getWidgetSchema()->getLabel('captcha')))?>
			<img id="contact_captcha_img" src="/captcha?t=<?php echo time()?>" width="94" height="23" alt=""/><br />
			<div class="sabuttoncenter"><p><a id="contactSubmit" href="#"><?php echo __('Send') ?></a></div>

	</form>
		<div class="clear"></div>
</div>

<script type="text/javascript">
// Released under MIT license: http://www.opensource.org/licenses/mit-license.php

$('[placeholder]').focus(function() {
  var input = $(this);
  if (input.val() == input.attr('placeholder')) {
    input.val('');
    input.removeClass('placeholder');
  }
}).blur(function() {
  var input = $(this);
  if (input.val() == '' || input.val() == input.attr('placeholder')) {
    input.addClass('placeholder');
    input.val(input.attr('placeholder'));
  }
}).blur().parents('form').submit(function() {
  $(this).find('[placeholder]').each(function() {
    var input = $(this);
    if (input.val() == input.attr('placeholder')) {
      input.val('');
    }
  })
});    
    
    
  $('#contactSubmit').click(function(e) {
	e.preventDefault();
	var button = $(this);

	if(button.attr('loading')=='1')return false;

	button.html('<?php echo __('wait') ?>');
	button.attr('loading', 1);
	
	var form = $(this).parents('form');
	var action = form.attr('action');

	$.post(action, form.serialize(), function(data) {
	  if(data.code == 500){ // fail
		  var errs = "";
		  for(var err in data.errors){
			  errs += data.errors[err] + "<br />";
		  }
		  $('#contact_errors').html(errs);
		  
		  // reload captcha
		  var img = $('#contact_captcha_img');
		  img.attr('src', img.attr('src') + '1');
                  
		  button.attr('loading', 0);
		  button.html('<?php echo __('saada') ?>');
	  }else{ // suxass
		form.html(data.notice);
                $('#contact_errors').html('');
        }
	   $('#content').tinyscrollbar_update();

	},'json');

    return false;
  });
</script>

<?php end_slot() ?>